package com.ziki.framework.wicket.markup.html.form;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.wicket.markup.html.form.IChoiceRenderer;

public class FwChoiceData<T> {
    private List<T> lstChoice;
    private Map<String, List<T>> mapChoice;
    private String displayExpression;
    private String idExpression;

    public FwChoiceData(List<T> lstChoice) {
        this.lstChoice = lstChoice;
        this.displayExpression = "value";
        this.idExpression = "id";
    }

    public FwChoiceData(List<T> lstChoice, String displayExpression, String idExpression) {
        this.lstChoice = lstChoice;
        this.displayExpression = displayExpression;
        this.idExpression = idExpression;
    }

    public FwChoiceData(Map<String, List<T>> mapChoice, String displayExpression, String idExpression) {
        List<T> lstChoice = new ArrayList<T>();
        for (String key : mapChoice.keySet()) {
            lstChoice.addAll(mapChoice.get(key));
        }
        this.mapChoice = mapChoice;
        this.lstChoice = lstChoice;
        this.displayExpression = displayExpression;
        this.idExpression = idExpression;
    }

    public IChoiceRenderer<T> getChoiceRender() {
        return new FwChoiceRenderer<T>(displayExpression, idExpression);
    }

    public List<T> getList() {
        return this.lstChoice;
    }

    public Map<String, List<T>> getGroupList() {
        return this.mapChoice;
    }

}
